
package com.thon.service.util;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.thon.dao.system.DicDataDao;
import com.thon.dao.util.DataAnalysisDao;
import com.thon.dao.util.Page;
import com.thon.entity.system.DicData;
import com.thon.entity.util.IdEntity;

/**
 * @file AbstractDataAnalysis.java
 * @author manpiaoyi
 * @email manpiaoyi@126.com
 * @date 2014-11-8
 * @description 数据分析服务
 */
public abstract class AbstractDataAnalysis<T extends IdEntity> implements DataAnalysis{
	
	
	@Autowired @Qualifier("DatabseAnalysis")
	private DataAnalysisDao<T> dataAnalysis;
	
	@Autowired @Qualifier("dicDataDaoImpl")
	private DicDataDao dicDataDao;	
	
	private Date startDate;
	private Date endDate;
	private Integer[] idA;
	private String ids;
	private List<T> datum ;
	private Page<T> pageDatum;
	
	
	public DataAnalysisDao<T> getDataAnalysis() {
		return dataAnalysis;
	}


	public void setDataAnalysis(DataAnalysisDao<T> dataAnalysis) {
		this.dataAnalysis = dataAnalysis;
	}


	public DicDataDao getDicDataDao() {
		return dicDataDao;
	}


	public void setDicDataDao(DicDataDao dicDataDao) {
		this.dicDataDao = dicDataDao;
	}


	public Date getStartDate() {
		return startDate;
	}


	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}


	public Date getEndDate() {
		return endDate;
	}


	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}


	public Integer[] getIdA() {
		return idA;
	}


	public void setIdA(Integer[] idA) {
		this.idA = idA;
	}


	public String getIds() {
		return ids;
	}


	public void setIds(String ids) {
		this.ids = ids;
	}


	public List<T> getDatum() {
		return datum;
	}


	public void setDatum(List<T> datum) {
		this.datum = datum;
	}


	public Page<T> getPageDatum() {
		return pageDatum;
	}


	public void setPageDatum(Page<T> pageDatum) {
		this.pageDatum = pageDatum;
	}


	@Override
	public  abstract void analyseData();	


	@Override
	public void readData() {		
		
		 datum =dataAnalysis.getDataList(startDate,endDate,ids);		
			
		
	}	
	
	public void readDataPage() {	
		 pageDatum =dataAnalysis.getDataPage(pageDatum,startDate,endDate,ids);
	}

	@Override
	public abstract void writeResult();
	
	
	public Map<Integer,String> getIdsMap(String ids){
	
		List<DicData>  dicList= dicDataDao.readList();
		Map<Integer,String> map= new HashMap<Integer,String>();
		String[] strArray = ids.split(",");
		if(dicList!=null)
		for(DicData dicData:dicList)
		{			
				for(int i=0;i<strArray.length;++i)
				{
					if(strArray[i].equals(dicData.getId().toString()))
						{ 
							map.put(dicData.getId(), dicData.getName());
						    break;
						}
				}
		}
		return map;		
	}	
	



}